package org.me.marble;

import java.nio.*;

import javax.microedition.khronos.opengles.GL10;

/**
 *
 * @author tungi
 */

public class PointObject2 extends AvailableObject{
	private float width;
    private FloatBuffer frontTriangleBuffer,backTriangleBuffer;

    public PointObject2(int id,float width){
        super(id);
        this.width=width;
        this.mwidth=width+0.25f;
    }

    @Override
    public void effect(GameRenderer _renderer,MoveMarble _mm){
        OptionsLibrary.points+=OptionsLibrary.difficulty_level;
    }

    @Override
    public void init(){
        //set the coordinates of this object's front side
        float[] fronttriangle={0.0f,-0.3f,0.0f,
        				  -width,0.1f,0.0f,
        				  0.0f,0.2f,0.0f,
        				  width,0.1f,0.0f
        };
        float[] backtriangle={0.0f,-0.3f,0.0f,
							  width,0.1f,0.0f,
							  0.0f,0.2f,0.0f,
							  -width,0.1f,0.0f
        };

        frontTriangleBuffer=BufferFactory.MakeFloatBuffer(fronttriangle);
        backTriangleBuffer=BufferFactory.MakeFloatBuffer(backtriangle);

        color=new MyColor();
        color.setAmbient(new float[]{0.0f,1.0f,0.0f,0.8f});
        color.setDiffuse(new float[]{0.0f,1.0f,0.0f,0.8f});
        color.setSpecular(new float[]{0.6f,0.6f,0.6f,0.7f});
        color.setEmission(new float[]{0.1f,0.1f,0.1f,0.6f});
        color.setShininess(1.0f);
    }

    @Override
    public void draw(GL10 gl){
    	gl.glTranslatef(centre.getX(),centre.getY(),centre.getZ());
        gl.glRotatef(angle,d.getX(),d.getY(),d.getZ());
        gl.glRotatef(dir_angle,up.getX(),up.getY(),up.getZ());

        OpenGLSystem.enable(gl,OpenGLSystem.CULL_FACE | OpenGLSystem.BLEND_IF_NO_FOG);
        OpenGLSystem.enableClientStates(gl,OpenGLSystem.NORMAL_ARRAY | OpenGLSystem.VERTEX_ARRAY);

        OpenGLSystem.setMaterial(gl,color);

        OpenGLSystem.drawTriangles(gl,null,frontTriangleBuffer,frontTriangleBuffer,
                null,4,GL10.GL_TRIANGLE_FAN);
        OpenGLSystem.drawTriangles(gl,null,backTriangleBuffer,backTriangleBuffer,
                null,4,GL10.GL_TRIANGLE_FAN);

        OpenGLSystem.disableClientStates(gl,OpenGLSystem.NORMAL_ARRAY | OpenGLSystem.VERTEX_ARRAY);
        OpenGLSystem.disable(gl,OpenGLSystem.CULL_FACE | OpenGLSystem.BLEND);
    }
}
